/**
 * Copyright 2006-2015 handu.com
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.iepacj.controller;

import com.alibaba.fastjson.JSON;
import com.iepacj.core.quartz.JobExecutor;
import com.iepacj.job.ExecOnceJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


@Controller
@RequestMapping("/job")
public class JobTestController {

	private static final Logger logger = LoggerFactory.getLogger(JobTestController.class);

	@ResponseBody
	@RequestMapping(value="/add", method={ RequestMethod.GET, RequestMethod.POST })
	public String createJob(String id) {
		Map<String, Object> dataMap = new HashMap<>();
		dataMap.put("id", id);
		
		Calendar cale = Calendar.getInstance();
		System.out.println("创建时间: " + cale.getTime());
		cale.set(Calendar.SECOND, cale.get(Calendar.SECOND) + 10);
		
		new JobExecutor().executeOnlyOnce(ExecOnceJob.class, cale.getTime(), dataMap);
		return JSON.toJSONString(dataMap);
	}


	@ResponseBody
	@RequestMapping(value="/detail", method={ RequestMethod.GET, RequestMethod.POST })
	public String getInquiryDetail(String id) {

		Map<String, Object> res = new HashMap<>();

		res.put("id", id);
		res.put("t", new Date());
		res.put("desc", "想知道你真的过得好么");
		res.put("stat", 2);

		if (logger.isDebugEnabled()) {
			logger.debug("result in isDebugEnabled::{}", JSON.toJSONString(res, true));
		}

		return JSON.toJSONString(res, true);
	}

}
















